<!-- 求助管理页面 -->
<template>
  <div class="help-manage">
    <el-container>
      <el-header height="40px" style="text-align: center">
        <!-- Header content -->
        <div class="banner">
          <span class="title">收藏列表</span>
        </div>
      </el-header>
      <el-main height="auto">
        <!-- Main content -->
        <el-table :data="dataList" style="width: 100%">
          <el-table-column label="标题" prop="postInfo.title"> </el-table-column>
          <el-table-column label="社区" prop="postInfo.communityName"> </el-table-column>
          <el-table-column label="发布者">
            <template slot-scope="scope">
              {{ scope.row.postInfo.pubUserName ?? scope.row.postInfo.pubNickName }}
            </template>
          </el-table-column>

          <el-table-column label="操作" align="center" width="250px">
            <template slot-scope="scope">
              <el-dropdown
                szie="mini"
                placement="bottom-end"
                style="margin-right: 10px"
                trigger="click"
              >
                <span class="el-dropdown-link">
                  <el-button type="text"
                    >选择动作<i class="el-icon-arrow-down el-icon--right"></i
                  ></el-button>
                </span>
                <el-dropdown-menu slot="dropdown" style="width: 96px">
                  <el-dropdown-item @click.native="goHelpDetail(scope.row.postId)"
                    >查看帖子</el-dropdown-item
                  >
                  <el-dropdown-item
                    @click.native="deleteHelp(scope.row.postId, scope.$index)"
                    >取消收藏</el-dropdown-item
                  >
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
      <el-footer height="35px" style="text-align: center">
        <!-- Footer content -->
        <el-pagination
          :page-size="params.pageSize"
          :current-page="params.pageNum"
          @current-change="changePageNum"
          layout="prev, pager, next"
          :total="total"
        >
        </el-pagination>
      </el-footer>
    </el-container>
  </div>
</template>

<script>
import * as API from "@/api/collect/collect";
export default {
  name: "helpManagement",
  data() {
    return {
      params: {
        pageSize: 10,
        pageNum: 1,
      },
      total: null,
      dataList: [],
    };
  },
  methods: {
    test() {},
    getList() {
      API.getCollectionList(this.params).then((res) => {
        console.log(res.data);
        this.dataList = res.data.rows;
        this.total = res.data.count;
      });
    },
    changePageNum(currentPage) {
      console.log(currentPage);
      //这里不能直接设置params里的属性因为默认的代理只会代理一层
      this.$set(this.params, "pageNum", currentPage);
    },
    deleteHelp(id, index) {
      API.cancelCollect({ postId: id }).then((res) => {
        this.getList();
        this.$message({
          message: "取消成功",
          type: "success",
        });
      });
    },
    goHelpDetail(id) {
      this.$router.push("/post/detail?id=" + id);
    },
  },
  watch: {
    params: {
      deep: true,
      handler: function (newValue, oldValue) {
        this.getList();
      },
    },
  },
  created() {
    this.getList();
  },
};
</script>

<style scoped>
* {
  margin: 0px;
  padding: 0px;
}
.help-manage {
  width: 100%;
  height: 100%;
  display: flex;
}
img {
  width: 35px;
  height: 35px;
  vertical-align: middle;
}
.title {
  font-size: 25px;
  color: rgb(163, 220, 243);
  display: inline-block;
  vertical-align: middle;
}
.el-button {
  margin-top: 0px !important;
}
.el-dropdown-menu__item {
  text-align: center;
}
</style>
